<?php
function uploadOne($img = 'picUrl', $type = 'thumb')
{
    $file = request()->file($img);
    write_log(json_encode($file));
    if (!empty($file)) {

        // 移动到框架应用根目录/public/uploads/ 目录下
        $upload = $file->move(ROOT_PATH . 'public' . DS . 'uploads');

        // halt($upload);
        if ($upload) {

            if ($type == 'thumb') {
                //图片处理
                imgDispose('public' . DS . 'uploads' . DS . $upload->getSaveName());
            }

            //返回图片地址
            return 'uploads/' . date('Ymd') . '/' . $upload->getFilename();
        }
        return $file->getError();
    }

    return request()->param($img,'');
}

function uploadOne1($img = 'picUrl', $type = 'thumb')
{
    $file = request()->file($img);

    if (!empty($file)) {

        // 移动到框架应用根目录/public/uploads/ 目录下
        $upload = $file->move(ROOT_PATH . 'public' . DS . 'uploads');

        // halt($upload);
        if ($upload) {

            if ($type == 'thumb') {
                //图片处理
                imgDispose('public' . DS . 'uploads' . DS . $upload->getSaveName());
            }

            //返回图片地址
            return 'uploads/' . date('Ymd') . '/' . $upload->getFilename();
        }
        return $file->getError();
    }
    return request()->param($img.'_url','');
}

function getDistance($lat1, $lng1, $lat2, $lng2){

    // 将角度转为狐度
    $radLat1 = deg2rad($lat1);// deg2rad()函数将角度转换为弧度
    $radLat2 = deg2rad($lat2);
    $radLng1 = deg2rad($lng1);
    $radLng2 = deg2rad($lng2);

    $a = $radLat1 - $radLat2;
    $b = $radLng1 - $radLng2;

    $s = 2 * asin(sqrt(pow(sin($a / 2), 2)+cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137;

    return $s;

}